package com.gthncz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.gthncz.beans.UserDetailsImpl;
import com.gthncz.mbg.dao.AuthRoleUserMapper;
import com.gthncz.mbg.pojo.AuthRoleUser;
import com.gthncz.service.UserService;

@Service
public class UserServiceImpl implements UserService, UserDetailsService{
	
	@Autowired
	private AuthRoleUserMapper authRoleUserMapper;

	@Override
	public AuthRoleUser findUserByUsername(String username) {
		AuthRoleUser user = authRoleUserMapper.findByUsername(username);
		return user;
	}

	@Override
	public List<AuthRoleUser> listUsers() {
		List<AuthRoleUser> users = authRoleUserMapper.listUsers();
		return users;
	}

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		AuthRoleUser user = findUserByUsername(username);
		UserDetailsImpl userDetailsImpl = new UserDetailsImpl(user);
		return userDetailsImpl;
	}

}
